package com.zhoujing.utils;

import java.util.Queue;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.android.volley.toolbox.NetworkImageView;

import android.R.integer;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.widget.ImageView;

public class ImageDownload_NetworkImageView {
	
	public static LruCache<String,Bitmap> getLruCache(Context context){
		LruCache<String,Bitmap> lruCache=null;
		int maxSize = ((ActivityManager) context
				.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass() / 8;
	     lruCache = new LruCache<String, Bitmap>(
				maxSize) {
			@Override
			protected int sizeOf(String key, Bitmap value) {
				// TODO Auto-generated method stub
				return value.getRowBytes() * value.getHeight();
			}
		};
		return lruCache;
		
		
	}

	public static void downLoadImage(RequestQueue queue,Context context,String path,NetworkImageView imageView,final LruCache<String,Bitmap> lruCache){
	
		ImageCache imageCache=new ImageCache() {
			
			@Override
			public void putBitmap(String url, Bitmap bitmap) {
				lruCache.put(url,bitmap);
				
			}
			
			@Override
			public Bitmap getBitmap(String url) {
				// TODO Auto-generated method stub
				return lruCache.get(url);
			}
		};
		
		ImageLoader imageLoader=new ImageLoader(queue,imageCache);
		imageView.setTag(path);
		imageView.setImageUrl(path, imageLoader);
	} 

}
